package com.example.boardroom.newItems;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.example.boardroom.R;
import com.example.boardroom.demo.times.AdapterTimeLitte;
import com.example.boardroom.demo.times.BeanTimes2;
import com.example.boardroom.demo.times.EventTimes;
import com.lxj.xpopup.core.CenterPopupView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

public class CustomPopup extends CenterPopupView {
    Context mContext;

    public CustomPopup(@NonNull Context context) {
        super(context);
        mContext = context;
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        stampList.clear();
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.custom_popup;
    }

    RecyclerView recyclerView2;
    HardwareControlStampAdapter stampAdapter;
    TextView tv_select;

    @Override
    protected void onCreate() {
        super.onCreate();
        stampList=new ArrayList<>();
        recyclerView2 = findViewById(R.id.recyclerview);
        recyclerView2.setLayoutManager(new LinearLayoutManager(getContext()));
        tv_select = findViewById(R.id.tv_select);
        initAdapter2();
        tv_select.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickListenerCUs.onClickCUs(v);
            }
        });
    }

    private void initAdapter2() {
        recyclerView2.setLayoutManager(new LinearLayoutManager(getContext()));
        stampAdapter = new HardwareControlStampAdapter(new ArrayList<>());


        recyclerView2.setAdapter(stampAdapter);
        stampAdapter.setEmptyView(R.layout.item_empty);
//        View errorView = getLayoutInflater().inflate(R.layout.error_view, mRecyclerView, false);
    }
    List<QueryTimeStamp> stampList;

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void getEvent(EventTimes event) {
        if (event.type == 2) {
            stampList= (List<QueryTimeStamp>) event.msg;
            LogUtils.i("lufei_event", "收到消息", stampList.size());
            if (null == stampAdapter) {
                LogUtils.i("lufei_event", "收到消息", "空对象");
            } else {
                stampAdapter.setList(stampList);
            }

        }

    }

    private OnClickListenerCUs onClickListenerCUs;

    public interface OnClickListenerCUs {
        /**
         * Called when a view has been clicked.
         *
         * @param v The view that was clicked.
         */
        void onClickCUs(View v);
    }

    public void setOnClickListenerCUs(OnClickListenerCUs l) {
        onClickListenerCUs=l;
    }
}
